package com.library.bookmanagement.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author ：ZXM
 * @date ：Created in 2020/5/26 16:29
 * @description：密码处理工具类
 */
public class PasswordUtil {
    // 采用md5用于password加密
    public static String md5(String source){
        if(source == null || source.length() == 0){
            throw new RuntimeException("密码转密错误");
        }
        String algorithm="md5";
        try {
            MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
            byte[] input = source.getBytes();
            byte[] output = messageDigest.digest(input);
            BigInteger bigInteger = new BigInteger(1, output);
            String encoded = bigInteger.toString(16).toUpperCase();
            return encoded;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
}
